<?php

namespace app\admin\controller\bet;

use app\common\controller\Backend;
use fast\Random;
use think\Db;

/**
 * 会员管理
 *
 * @icon fa fa-user
 */
class Bet extends Backend
{

    protected $relationSearch = true;

    /**
     * User模型对象
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('ApplyBet');
    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax())
        {
            $map = [];
            // 判断是不是超级管理员
            if ( !$this->auth->isSuperAdmin() ){
                $map['admin_id'] = $this->auth->id;
            }

            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }


            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $total = $this->model
                ->with('user,admin,apply')
                ->where($where)
                ->where($map)
                ->order($sort, $order)
                ->count();


            $list = $this->model
                ->with('user,admin,apply')
                ->where($where)
                ->where($map)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

}
